package com.mandao;

import com.mandao.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

/**
 * @author snail
 * consumer-hystrix
 */
@SpringBootApplication
@RestController
@EnableCircuitBreaker //启动熔断器
public class BookReadApplication {

	@Autowired
	private BookService bookService;

	/**
	 *此种方式不能起到融合熔断的作用，因此如果服务提供者故障，程序得到500异常。
	 */
	@RequestMapping("/to-read")
	public String readingList(){
		RestTemplate restTemplate = new RestTemplate() ;
		URI uri = URI.create("http://localhost:1111/recommended") ;
		return restTemplate.getForObject(uri , String.class);
	}

	@GetMapping("/read")
	public String reading(){
		return bookService.readingList();
	}

	public static void main(String[] args) {
		SpringApplication.run(BookReadApplication.class, args);
	}

}
